<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    protected function _initDoctype() {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('XHTML1_STRICT');
    }

    protected function _initAutoload()
	{
		$autoloader = new Zend_Application_Module_Autoloader(array('namespace' => 'Application_','basePath'  => dirname(__FILE__),));
	    	return $autoloader;
	}

 	public function _initDbNames()
	{
		try
		{
			$config = array('host' => 'localhost','username' => 'root','password' => 'kwasik','dbname'   => 'logistic',);
	    		$db = Zend_Db::factory('PDO_MYSQL', $config);
	    		Zend_Db_Table::setDefaultAdapter($db);
	    		$db->query('SET NAMES UTF8');
	    	}
	    	catch (Exception $e)
	    	{
	        	echo "Blad polaczenia z baza danych: ".$e->getMessage();
	        	exit(0);
	    	}
	}

    protected function _initView() {
        $view = new Zend_View();
        $view->doctype('XHTML1_STRICT');
        $view->headTitle('System wspomagania przesyłek kurierskich');
        $view->skin = 'standardowy';
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $viewRenderer->setView($view);
        return $view;
    }

    public function _initLayoutBasic() {
       $auth = Zend_Auth::getInstance();
		if ($auth->hasIdentity())
        	{
			$identity = $auth->getIdentity();
                        switch($identity->rola) {
                case '1':
                    $options = array('layout' => 'nadawca');
                    break;

                case '2':
                    $options = array('layout' => 'kurier');
                    break;

                case '3':
                    $options = array('layout' => 'magazyn');
                    break;

                
            }
        } else {
            $options = array('layout' => 'layout');
        }

        Zend_Layout::startMvc($options);
    }

}

